<template>
<div>
  <Header></Header>
    	<!--创建活动开始-->
		<div class="editBox w1200 bc b87 bg100 pb50 mt30 mb30 " >
			<h1 class="w h40 bg95 c_grn_119c5b fb f14 lh40 bb87 text-left"><img src="../../../static/images/write.png"  class="ml20 mr10 vm">发布活动</h1>
			<table class=" edit_tb f14 lh24 mt40  ml50 mr50">
					<col class="w140"/>
					<col />
			<!--活动地址-->
				<tr >
					<td class="tr vt">
						<span class="inline-block c20 w100 h24 tr mr20"><i class="f14 lh24 fm_songti c_orgRed_ff481d mr5">*</i>活动地址:</span>
					</td>
					<td class="clearfix">
            <el-select v-model="seleprovince" placeholder="请选择" @change="selectFun">
              <el-option
                v-for="(item,index) in province"
                :key="item.value"
                :label="item.label"
                :value="index+'|province'">
              </el-option>
            </el-select>
            <el-select v-model="selecity" placeholder="请选择" @change="selectFun">
              <el-option
                v-for="(item,index) in city"
                :key="item.value"
                :label="item.label"
                :value="index+'|city'">
              </el-option>
            </el-select>
            <el-select v-model="seleregin" placeholder="请选择" @change="selectFun">
              <el-option
                v-for="(item,index) in Region"
                :key="item.value"
                :label="item.label"
                :value="index+'|regin'">
              </el-option>
            </el-select>
					</td>
				</tr>
				<!--活动标题-->
				<tr >
					<td class="tr vt">
						<span class="inline-block c20 w100 h24 tr mr20"><i class="f14 lh24 fm_songti c_orgRed_ff481d mr5">*</i>活动标题:</span>
					</td>
					<td>
						<input class="fl w482 h40  f12 lh40 c40 t1 b87 acTitle" v-model="addData['activityName']" type="text" name="" value="" style="border-radius:4px;"/>
					</td>
				</tr>
        <!--活动封面图-->
        <tr >
          <td class="tr vt">
            <span class="inline-block c20 w100 h24 tr mr20"><i class="f14 lh24 fm_songti c_orgRed_ff481d mr5">*</i>活动封面图:</span>
          </td>
          <td>
            <wwUpload @reloadImg="reloadMainPic" @uploadStateFun="uploadStateFun" ></wwUpload>
            <img v-if="addData['coverImgUrl']" :src="addData['coverImgUrl']+'?x-oss-process=image/resize,m_fill,h_150,w_220' " alt="" style="margin-top:15px;">
          </td>
        </tr>
				<!--开始时间-->
				<tr >
					<td class="tr vt">
						<span class="inline-block c20 w100 h24 tr mr20"><i class="f14 lh24 fm_songti c_orgRed_ff481d mr5">*</i>开始时间:</span>
					</td>
					<td>
						<div class="block">
                <el-date-picker
                v-model="addData['startTime']"
                type="datetime"
                placeholder="选择日期时间"
                :picker-options="pickerOptions"
                @change = "startTimeOver">
                </el-date-picker>
            </div>
					</td>
				</tr>
				<!--结束时间-->
				<tr >
					<td class="tr vt">
						<span class="inline-block c20 w100 h24 tr mr20"><i class="f14 lh24 fm_songti c_orgRed_ff481d mr5">*</i>结束时间:</span>
					</td>
					<td>
						<div class="block">
                <el-date-picker
                v-model="addData['endTime']"
                type="datetime"
                placeholder="选择日期时间"
                :picker-options="pickerOptions"
                @change="endTimeOver">
                </el-date-picker>
            </div>
					</td>
				</tr>
				<!--活动场地-->
				<tr>
					<td class="tr vt " style="padding-bottom:0;">
						<span class="inline-block c20 w100 h24 tr mr20"><i class="f14 lh24 fm_songti c_orgRed_ff481d mr5">*</i>活动场地:</span>
					</td>
					<td class="clearfix vt pb10" style="padding-bottom:0;">
						<a href="javascript:void(0);" class="fl f12 c40 addIcon h40 pl40 pr20 mr20 mb20 b_grn_119c5b br2 pointer lh40 addPlaceBtn" @click="addPlace">点击添加</a>
						<a href="javascript:void(0);" v-for="(item, index) in selectPlaceName" class="fl f12 h40 pl20 pr20 mr20 mb20  bg_grn_119c5b br2 fm_songti  lh40 c100 pr hoverbg_org">{{item['name']}}
              <i class="redCloseX" @click="delPlace(index)"></i>
            </a>
					</td>
				</tr><!--活动场地结束-->
				<!--选择场地弹出框-->
				<tr class="" v-show="addshowState">
					<td class="tr vt"></td>
					<td >
						<!--场地 弹出框 主体-->
							<div class="fl pr p20  br2 bg100 b_org_f16113 w614">
								<img  class="pa orgArr_up" src="../../../static/images/org_arrow_up.png" width="28" height="18"/>
								<table class="pr60 ">
									<tr>
										<td class="tr vt" style="padding-bottom:20px;">
											<span class="inline-block c20 w100 h24 mr20">选择场地:</span>
										</td>
										<td style="padding-bottom:20px;">
                      <el-select v-model="placeAreaData['seleprovince']" placeholder="请选择" @change="selectFunPlace" style="width:215px;">
                        <el-option
                          v-for="(item,index) in province"
                          :key="item.value"
                          :label="item.label"
                          :value="index+'|province'">
                        </el-option>
                      </el-select>
                      <el-select v-model="placeAreaData['selecity']" placeholder="请选择" @change="selectFunPlace" style="width:215px;">
                        <el-option
                          v-for="(item,index) in placeAreaData['city']"
                          :key="item.value"
                          :label="item.label"
                          :value="index+'|city'">
                        </el-option>
                      </el-select>
										</td>
									</tr>

									<tr>
										<td class="tr vt" style="padding-bottom:20px;">
										</td>
										<td style="padding-bottom:20px;">
                      <el-checkbox-group v-model="selectPlace" @change="handleSelectPlaceFun">
                        <el-checkbox v-for="list in placeList" :label="list.id" style="width:145px;margin-right:5px;margin-left:0px;overflow: hidden" :title="list.placeName">{{list.placeName}}</el-checkbox>
                      </el-checkbox-group>
										</td>
									</tr>

									<!--添加按钮-->
									<tr>
										<td class="tr vt">
											<span class="inline-block c20 w100 h24 mr20"></span>
										</td>
										<td>
											<a href="javascript:void(0);" class="inline-block w100 h40 fm f12 c100 lh40 tc letter2 bg_grn_119c5b  b2 hoverbg_orgred" @click="surePlaceBtn">确定</a>
										</td>
									</tr>
								</table>
							</div><!--场地 弹出框结束-->
					</td>
				</tr><!--选择场地弹出框结束-->
				<!--集合地点-->
				<tr >
					<td class="tr vt">
						<span class="inline-block c20 w100 h24 tr mr20"><i class="f14 lh24 fm_songti c_orgRed_ff481d mr5">*</i>集合地点：</span>
					</td>
					<td class="vt">
						<div id="mapContainer"  class="= w655 h370  f12 lh24 c40 t1 b87" >
              <!--<div id="mapContainer" class="fl w400 h200  f12 lh24 c40 t1 b87" ></div>-->
              <!--<div id="tip">-->
                <!--<input type="text" id="keyword" name="keyword" v-model="searchKeyWord" value="请输入关键字：(选定后搜索)" onfocus='this.value=""'  @change="searchMap"/>-->
              <!--</div>-->
            </div>
						<div class="mt20">
							<span class="inline-block c20 h24 lh24 ">详细地址：</span>
							<input class=" w438 h40  f12 lh40 c40 t1 b87" v-model="addData['address']"  type="text" name="" value="" />
						</div>
					</td>
				</tr>
				<!--集合地点结束-->
				<!--活动费用-->
				<tr >
					<td class="tr vt">
						<span class="inline-block c20 w100 h24 tr mr20">活动费用：</span>
					</td>
					<td class="vt">
						<div class="f12 lh24 c50 vm" >
              <el-radio-group v-model="moneyType">
                <el-radio :label="0">免费</el-radio>
                <el-radio :label="1">现场收费</el-radio>
              </el-radio-group>
						</div>
					</td>
				</tr>
				<!--活动费用结束-->
				<!--活动人数-->
				<tr class="">
					<td class="tr vt">
						<span class="inline-block c20 w100 h24 tr mr20">活动人数：</span>
					</td>
					<td >
              <input class=" w438 h40  f12 lh40 c40 t1 b87" v-model="addData['limitCount']"  type="number" name="" value="" placeholder="请输入活动人数(1-100人)"/>
					</td>
				</tr><!--选择场地弹出框结束-->
				<!--活动介绍-->
				<tr>
					<td class="tr vt">
						<span class="inline-block c20 w100 h24 mr20">活动介绍：</span>
					</td>
					<td class="clearfix vt">
            <Ue @jsonDetail = "jsonDetail" :json-description = "addData['jsonDescription']" v-if="showUe" :type="'active'"></Ue>
					</td>
				</tr>
				<!--活动介绍结束-->
				<!--行程安排-->
				<!--<tr>-->
					<!--<td class="tr vt">-->
						<!--<span class="inline-block c20 w100 h24 mr20">行程安排：</span>-->
					<!--</td>-->
					<!--<td class="clearfix vt">-->
						<!--<textarea class=" b87 br2 f14 lh180 t1 h372 p10" style="width:655px;" v-model="addData['scheduling']" name="#" rows="" cols="" placeholder="请输入活动介绍，500字以内"></textarea>-->
					<!--</td>-->
				<!--</tr>-->
				<!--行程安排结束-->
				<!--活动介绍图-->
				<tr>
					<td class="tr vt">
						<span class="inline-block c20 w100 h24 mr20">活动介绍图：</span>
					</td>
					<td class="clearfix vt">
						<div class="fl w100 h60 mr20 pr b87 bg98 f14 lh60 c40 vm tc pointer hoverborder_orgred ">
						 	<img class="vm mr5" src="../../../static/images/grayAdd.png" />
						 	<span class="vm">继续添加</span>
              <wwUpload @reloadImg="reloadPic" @uploadStateFun="uploadStateFun" style="width:100%;height:100%;position: absolute;top:0px;left:0px;opacity: 0" ></wwUpload>
						</div>
						<a href="javascript:void(0);" class="fl w100 h60 mr20 mb10 pr" v-for = "(item, index) in picList">
              <img :src="item['flag']===1?item['fileName']+'?x-oss-process=image/resize,m_fill,h_60,w_100':item['thumFileName']+'?x-oss-process=image/resize,m_fill,h_60,w_100'" width="100" height="60"/>
              <i class="redCloseX" @click="delPic(index)"></i>
            </a>
					</td>
				</tr>
				<!--活动介绍图结束-->
				<!--领队名字-->
				<tr>
					<td class="tr vt">
						<span class="inline-block c20 w100 h24 mr20">领队名字：</span>
					</td>
					<td>
						<input class="fl w300 h40  f12 lh40 c40 t1 b87" v-model="addData['initiatorName']"  type="text" name="" value="" />
					</td>
				</tr>
				<!--领队名字结束-->
				<!--联系方式-->
				<tr>
					<td class="tr vt">
						<span class="inline-block c20 w100 h24 mr20">联系方式：</span>
					</td>
					<td>
						<input class="fl w300 h40  f12 lh40 c40 t1 b87" v-model="addData['initiatorPhone']"  type="text" name="" value="" />
					</td>
				</tr>
				<!--联系方式方式结束-->
				<!--领队费用-->
				<!--<tr>-->
					<!--<td class="tr vt">-->
						<!--<span class="inline-block c20 w100 h24 mr20">领队费用：</span>-->
					<!--</td>-->
					<!--<td>-->
						<!--<input class="fl w160 h40  f12 lh40 c40 t1 b87"  type="text" name="" id="" value="" /><span class="ml5 lh40">元</span>-->
					<!--</td>-->
				<!--</tr>-->
				<!--领队费用结束-->

				<!--发布活动按钮-->
				<tr>
					<td class="tr vt ">
						<span class="inline-block c20 w100 h24 mr20"></span>
					</td>
					<td>
						<a href="javascript:void(0);" class="inline-block w160 h40 fm_yahei f16 fb c100 lh40 tc letter2 bg_grn_119c5b  br4 hoverbg_orgred" @click="addActivityData">发布活动</a>
					</td>
				</tr>

			</table>

		</div><!--创建场地结束-->
  <Footer></Footer>
  <loading v-show="loadState"></loading>
</div>
</template>
<script>
import Header from '../../components/header'
import Footer from '../../components/footer'
import Utils from '../../assets/Util'
import loading from '../../components/loading'
import Ue from '../../components/ue'
import wwUpload from '../../components/wwUpload'
export default {
  components: {
    Header,
    Footer,
    loading,
    Ue,
    wwUpload
  },
  data () {
    return {
        showUe:false,
        loadState:true,
        addshowState:false,
        province:[],
        city:[],
        Region:[],
        seleprovince:"",
        selecity:"",
        seleregin:"",
        seleprovinceid:"",
        selecityid:"",
        selereginid:"",
        seleprovinceIndex:0,
        selecityIndex:0,
        searchKeyWord:"请输入关键字：(选定后搜索)",
        entryLng:0,
        entryLat:0,
        moneyType:0,
        picList:[],
        getPlaceData:{
          provinceID:0,
          cityID:0,
          pageIndex: 0,
          pageSize: 15
        },
        placeList:[],
        selectPlace:[],
        selectPlaceName:[],
        placeAreaData:{
          province:[],
          city:[],
          Region:[],
          seleprovince:"",
          selecity:"",
          seleregin:"",
          seleprovinceid:"",
          selecityid:"",
          selereginid:"",
          seleprovinceIndex:0,
          selecityIndex:0
        },
        pickerOptions: {
          disabledDate(time) {
            return time.getTime() < Date.now();
          }
        },
        addData:{
          "token": localStorage.getItem('token'),
          "placeIDs": "",
          "activityName": "",
          "difficulty": 0,
          "imgUrl": "",
          "coverImgUrl": "",
          "setAddress": "",
          "initiatorName": "",
          "initiatorPhone": "",
          "limitCount": 0,
          "UserID": 0,
          "startTime": "",
          "endTime": "",
          "activityDescripition": "",
          "scheduling": "",
          "cost": 0,
          "costAmount": 0,
          "countryID": 0,
          "provinceID": 0,
          "cityID": 0,
          "regionID": 0,
          "address": "",
          "lng": 0,
          "lat": "",
          "motionIDs": "",
          "jsonDescription": ""
        }
    }
  },
  mounted(){
    this.getArea();
    this.init();
    this.$nextTick(() => {
      this.getActEditStatus();
    })
  },
  methods: {
    // 获取热门省市区
    getArea(){
      let that = this;
      let areaProps = {
        url:"/Common/GetArea",
        sCallBack:(res) => {
          let item = res.data.data.listProvince;
          that.allArea = item;
          item.forEach(element => {
            that.province.push({'label':element.name, 'value':element.id})
          });
          that.loadState = false;
          that.mainConState = true;
        },
        eCallBack:(err) => {
          console.log(err);
        }
      }
      Utils.myRequest(areaProps);
    },
    // 选择地址
    selectFun(e){
      let eArr = e.split("|");
      let index = eArr[0];
      let name = eArr[1];
      let that = this;
      switch (name) {
        case "province":
          let cityArr = that.allArea[index]["data"];
          that.city = [];
          cityArr.forEach(element => {
            that.city.push({'label':element.name, 'value':element.id})
          });
          that.seleprovinceIndex = index;
          that.addData.provinceID = that.allArea[index]["id"];
          that.selecity = "请选择";
          that.seleregin = "请选择";
          that.Region = [];
          break;
        case "city":
          let reginArr = that.allArea[that.seleprovinceIndex]["data"][index]['data'];
          that.Region = [];
          reginArr.forEach(element => {
            that.Region.push({'label':element.name, 'value':element.id})
          });
          that.selecityIndex = index;
          that.addData.cityID = that.allArea[that.seleprovinceIndex]["data"][index]['id'];
          that.seleregin = "请选择";
          break;
        case "regin":
          that.addData.regionID = that.allArea[that.seleprovinceIndex]["data"][that.selecityIndex]['data'][index]['id'];
          let seleProvinceIndex = that.seleprovince.split("|")[0];
          let seleCityIndex = that.selecity.split("|")[0];
          let seleReginIndex = that.seleregin.split("|")[0];
          let address = that.allArea[seleProvinceIndex]['name'] + "-" + that.allArea[seleProvinceIndex]['data'][seleCityIndex]['name'] + "-" + that.allArea[seleProvinceIndex]['data'][seleCityIndex]['data'][seleReginIndex]['name'];
          that.addData.address = address;
          break;
      }
    },
    selectFunPlace(e){
      let eArr = e.split("|");
      let index = eArr[0];
      let name = eArr[1];
      let that = this;
      switch (name) {
        case "province":
          let cityArr = that.allArea[index]["data"];
          that.placeAreaData.city = [];
          cityArr.forEach(element => {
            that.placeAreaData.city.push({'label':element.name, 'value':element.id})
          });
          that.placeAreaData.seleprovinceIndex = index;
          that.placeAreaData.selecity = "请选择";
          that.placeAreaData.seleregin = "请选择";
          that.getPlaceData.provinceID = that.allArea[index]["id"];
          break;
        case "city":
          that.placeAreaData.selecityIndex = index;
          that.getPlaceData.cityID = that.allArea[that.placeAreaData.seleprovinceIndex]["data"][index]['id'];
          break;
      }
      this.$nextTick(() => {
        this.loadState = true;
        this.getPlace();
      });
    },
    addPlace(){
      this.addshowState = !this.addshowState;
    },
    surePlaceBtn(){
      this.addshowState = false;
    },
    getPlace(){
      let props = {
        url:'/Place/GetList',
        data:this.getPlaceData,
        sCallBack:res => {
          if(res.data.code === 1){
            this.placeList = res.data.data;
          }else{
            this.$message.error("请求失败");
          }
          this.loadState = false;
        },
        eCallBack:err => {
          console.log(err);
        }
      }
      Utils.myRequest(props);
    },
    handleSelectPlaceFun(value){
      let selectPlaceArr = [];
      let that = this;
      value.forEach(function (item, index) {
        that.placeList.forEach(function (place) {
          if(place.id === item){
              let selectPlace = {
                id:item,
                name:place.placeName
              };
            selectPlaceArr.push(selectPlace);
          }
        })
      });
      this.$nextTick(function () {
        selectPlaceArr.forEach((selectPlace, index) => {
          if (JSON.stringify(that.selectPlaceName).indexOf(JSON.stringify(selectPlace)) == -1) {
            that.selectPlaceName.push(selectPlace);
          }
        });
      })
    },
    delPlace(index){
        this.selectPlace.splice(index, 1);
        this.selectPlaceName.splice(index, 1);
    },
    init(){
      let that = this;
      let MapConfig = this.entryLng === 0 ? {
        resizeEnable: true,
        zoom: 10, // 地图显示的缩放级别
        keyboardEnable: false
      } : {
        resizeEnable: true,
        center: [that.entryLng, that.entryLat],
        zoom: 10, // 地图显示的缩放级别
        keyboardEnable: false
      };
      let map = new AMap.Map("mapContainer", MapConfig);
      let marker = new AMap.Marker({
        position: map.getCenter(),
        draggable: true,
        cursor: 'move',
        raiseOnDrag: true
      });
      marker.setMap(map);
      map.on('click', function(e) {
        that.entryLat = e.lnglat.getLat();
        that.entryLng = e.lnglat.getLng();
        that.addData.lng = e.lnglat.getLng();
        that.addData.lat = e.lnglat.getLat();
        marker.setPosition([e.lnglat.getLng(), e.lnglat.getLat()]);
      });
      this.amap = map;
    },
    // 搜索位置
    searchMap(){
      let that = this
      AMap.plugin(['AMap.Autocomplete', 'AMap.PlaceSearch'], function(){
        var autoOptions = {
          city: "", // 城市，默认全国
          input: "keyword"// 使用联想输入的input的id
        };
        let autocomplete = new AMap.Autocomplete(autoOptions);
        let placeSearch = new AMap.PlaceSearch({
          pageSize: 1,
          pageIndex: 1,
          city:'杭州',
          map:that.amap
        })
        AMap.event.addListener(autocomplete, "select", function(e){
          placeSearch.setCity(e.poi.adcode);
          placeSearch.search(e.poi.name)
        });
      });
      AMap.service(["AMap.PlaceSearch"], function() {
        let placeSearch = new AMap.PlaceSearch({
          pageSize: 1,
          pageIndex: 1,
          city: "010",
          map: that.amap
        });
        placeSearch.search(that.searchKeyWord, function(status, result) {
          console.log(result);
        });
      });
    },
    jsonDetail(e){
      this.addData.jsonDescription = e.jsonStr
    },
    reloadPic(data){
      this.loadState = false;
      let Pic = {};
      if(data.flag && data.flag === "2"){
        let img = new Image();
        img.src = data['thumFileName'];
        img.onload = function(){
          Pic['imgWidth'] = img.width;
          Pic['imgHeight'] = img.height;
        };
        Pic['fileName'] = data['fileName'];
        Pic['flag'] = 2;
        Pic['thumFileName'] = data['thumFileName'];
        Pic['description'] = "";
        Pic['length'] = 0;
        this.picList.unshift(Pic);
      }else{
        let upInfo = data.files;
        let img = new Image();
        img.src = upInfo['url'];
        img.onload = function(){
          Pic['imgWidth'] = img.width;
          Pic['imgHeight'] = img.height;
        };
        Pic['fileName'] = upInfo['url'];
        Pic['flag'] = 1;
        Pic['thumFileName'] = "";
        Pic['description'] = "";
        Pic['length'] = 0;
        this.picList.push(Pic);
      }
    },
    uploadStateFun(){
      this.loadState = true;
    },
    delPic(index){
      this.picList.splice(index, 1);
    },
    // 封面图
    reloadMainPic(data){
      this.loadState = false;
      if(data.flag && data.flag === "2"){
          this.$message.warning('文件格式不对');
      }else{
        let upInfo = data.files;
        this.addData.coverImgUrl = upInfo['url'];
      }
    },
    addActivityData(){
      let that = this;
      let subUrl = "";
      this.addData['token'] = localStorage.getItem('token');
      this.addData['UserID'] = localStorage.getItem('uId');
      if (this.addData.provinceID === 0 || this.addData.provinceID === ""){
        this.$message.warning("请选择省份");
        return false;
      }
      if (this.addData.cityID === 0 || this.addData.cityID === ""){
        this.$message.warning("请选择城市");
        return false;
      }
      if (this.addData.regionID === 0 || this.addData.regionID === ""){
        this.$message.warning("请选择区");
        return false;
      }
      if(this.addData['activityName'] === "" || this.addData['activityName'] === null){
        this.$message.warning("请输入活动标题");
        return false;
      }
      if (this.addData['coverImgUrl'] === "" || this.addData['coverImgUrl'] === null){
        this.$message.warning("请上传活动封面图");
        return false;
      }
      if (this.addData['startTime'] === "" || this.addData['startTime'] === null){
        this.$message.warning("请选择活动开始时间");
        return false;
      }
      if (this.addData['endTime'] === "" || this.addData['endTime'] === null){
        this.$message.warning("请选择活动结束时间");
        return false;
      }
      if (this.selectPlaceName.length === 0){
        this.$message.warning("请选择关联场地");
        return false;
      }else{
        let placeIds = [];
        this.selectPlaceName.forEach((place) => {
            placeIds.push(place.id);
        })
        this.addData.placeIDs = placeIds.toString();
      }
      if(this.addData['lng'] === 0 || this.addData['lat'] === 0){
        this.$message.warning("请标记地图地址");
        return false;
      }
      if(this.addData['address'] === "" || this.addData['address'] === null){
        this.$message.warning("请输入详细地址");
        return false;
      }
      if (this.addData['limitCount'] === 0 || this.addData['limitCount'] === "" || this.addData['limitCount'] > 100){
        this.$message.warning("请输入正确的活动人数");
        return false;
      }
      if (this.addData['jsonDescription'] === "" || this.addData['jsonDescription'] === null){
        this.$message.warning("请输入活动介绍");
        return false;
      }
      // if (this.addData['scheduling'] === null || this.addData['scheduling'] === ""){
      //   this.$message.warning("请输入活动行程安排");
      //   return false;
      // }
      if (this.picList.length === 0){
        this.$message.warning("请上传活动介绍图");
        return false;
      }else{
        let Urls = [];
        this.picList.forEach((pic) => {
            Urls.push(pic['fileName']);
        })
        this.addData['imgUrl'] = Urls.toString();
      }

      if (this.addData['initiatorName'] === null || this.addData['initiatorName'] === ""){
        this.$message.warning("请输入领队名字");
        return false;
      }
      let zergTel = /^1(3|4|5|7|8)\d{9}$/;
      if (!zergTel.test(this.addData['initiatorPhone'])){
        this.$message.warning("请输入正确的手机号");
        return false;
      }
      this.loadState = true;
      if(this.$route.query.id){
        this.addData['id'] = this.$route.query.id;
        subUrl = "/Activity/Update";
      }else{
        subUrl = "/Activity/Add";
      }
      let props = {
        url:subUrl,
        data:this.addData,
        sCallBack: res => {
          this.loadState = false;
          if(res.data.code === 4){
            that.refreshToken(that.addActivityData());
          }else if(res.data.code === 1){
            that.$message.success("提交成功");
            setTimeout(function () {
              window.scrollTo(0, 0);
              that.$router.push({path:'/activityList'});
            }, 500);
          }else{
            that.$message.error("提交失败，稍后再试");
          }
        },
        eCallBack: err => {
          this.loadState = false;
          console.log(err);
          that.$message.error("系统出错，稍后再试");
        }
      }
      Utils.myRequest(props);
    },
    // 刷新token
    refreshToken(callBack){
      let refresh = {
        url:"/user/GetToken",
        data:{
          token:localStorage.getItem('token')
        },
        sCallBack:(res) => {
          localStorage.setItem("token", res.data.data)
          callBack && callBack();
        },
        eCallBack:(err) => {
          console.log(err);
        }
      }
      Utils.myRequest(refresh);
    },
    startTimeOver(value){
      if (this.addData['endTime'] && value > this.addData['endTime']) {
        this.$message.warning("开始时间不能大于结束时间");
        this.addData['startTime'] = "";
      }
    },
    endTimeOver(value){
      if (this.addData['startTime'] && value < this.addData['startTime']) {
        this.$message.warning("结束时间不能小于开始时间");
        this.addData['endTime'] = "";
      }
    },
    // 判断是新增还是修改
    getActEditStatus(){
      let that = this;
      let actId = this.$route.query.id;
      if(actId){
          let props = {
            url:"/Activity/GetDetails",
            data:{
              "id": actId,
              "userID": localStorage.getItem("uId")
            },
            sCallBack:res => {
              if(res.data.code === 1){
                this.seleprovince = res.data.data.provinceName;
                this.selecity = res.data.data.cityName;
                this.seleregin = res.data.data.regionName;
                this.addData.activityName = res.data.data.activityName;
                this.addData.coverImgUrl = res.data.data.coverImgUrl;
                this.addData.startTime = res.data.data.startTime;
                this.addData.endTime = res.data.data.endTime;
                this.addData.address = res.data.data.address;
                this.addData.limitCount = res.data.data.limitCount;
                this.addData.jsonDescription = res.data.data.jsonDescription;
                this.addData.initiatorName = res.data.data.initiatorName;
                this.addData.initiatorPhone = res.data.data.initiatorPhone;
                this.addData.provinceID = res.data.data.provinceID;
                this.addData.cityID = res.data.data.cityID;
                this.addData.regionID = res.data.data.regionID;
                this.addData.lng = res.data.data.lng;
                this.addData.lat = res.data.data.lat;
                this.moneyType = res.data.data.cost;
                if(res.data.data.imgUrl != ""){
                  let picArr = res.data.data.imgUrl.split(",");
                  picArr.forEach((pic, index) => {
                    let picObj = {};
                    picObj['fileName'] = pic;
                    picObj['flag'] = 1;
                    picObj['thumFileName'] = "";
                    picObj['description'] = "";
                    picObj['length'] = 0;
                    that.picList.push(picObj);
                  });
                }
                res.data.data.activityPlaceList.forEach(place => {
                    let placeName = {
                      id:place['placeID'],
                      name:place['placeName']
                    }
                    that.selectPlaceName.push(placeName);
                });
                this.showUe = true;
              }else{
                this.$message.error("活动详情请求失败");
              }
            },
            eCallBack:err => {
              console.log(err);
            }
          }
          Utils.myRequest(props);
      }else{
        this.showUe = true;
      }

    }
  }
}
</script>
<style lang="less" scoped>
.text-left{
    text-align: left;
}
.block{
    text-align: left;
}
.tr span{
    height: 40px;
    line-height: 40px;
}
.edit_tb td{
    padding-bottom:20px;
}
.acTitle:focus{
  border-color: #409EFF;
}
.addPlaceBtn:hover{
  border:1px solid #f16113;
}
</style>
